package com.thinkgem.jeesite.modules.quartz.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.thinkgem.jeesite.modules.quartz.service.SchedulejobService;



public class JobListener implements ServletContextListener ,ApplicationContextAware{

	/**
	 * 通过listenser方法，在服务器启动时自动启动状态为1的quartz任务
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
		SchedulejobService jobService = springContext.getBean(SchedulejobService.class);
		try {
			jobService.init();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		
	}
	
}
